Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kulish D. Flow Homework #64

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Kulish D. Flow Homework #64

wants to merge 4 commits into from

Conversation

Equin
Copy link

@Equin Equin commented Apr 25, 2022

No description provided.

2. Поменяйте реализацию с `LiveData` на `StateFlow`
3. В случае если возникнет ошибка в стриме, нужно заэмитить айтем `Result.Error`*

*Создать sealed класс `Result`. Унаследовать от него классы `Success<T>`, `Error`. Использовать эти классы как стейт необходимый для рендеринга/отображени ошибки
catsRepository.listenForCatFacts().collect {
_catsLiveData.value = it
}
withContext(Dispatchers.Main) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а нужна ли нам смена контекста, если viewmodelscope все запускает на Main диспатчере?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет не нужна, забыл что viewmodelscope на Main-е )

@@ -14,8 +19,25 @@ class MainActivity : AppCompatActivity() {
val view = layoutInflater.inflate(R.layout.activity_main, null) as CatsView
setContentView(view)

catsViewModel.catsLiveData.observe(this){
view.populate(it)
lifecycleScope.launch {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

есть еще функция launchWhenStarted из ktx пакета, немного сократит код

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants